﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace OF.Common
{
    public class Cookie
    {
        /// <summary>
        /// 增加cookie
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        public static void addCookie(string name,string value)
        {
            HttpCookie cookie = new HttpCookie(name);
            cookie.Value = value;
            HttpContext.Current.Response.AppendCookie(cookie);
        }

        /// <summary>
        /// 获取cookie值
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static string getCookie(string name)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[name];
            if (cookie != null)
            {
                return cookie.Value;
            }
            return "";
        }

        /// <summary>
        /// 删除cookie
        /// </summary>
        /// <param name="name"></param>
        public static void deleteCookie(string name)
        {
            HttpCookie cookie = HttpContext.Current.Request.Cookies[name];
            if (cookie != null)
            {
                cookie.Expires = System.DateTime.Now.AddDays(-1);
                HttpContext.Current.Response.Cookies.Add(cookie);
            }
        }

    }
}
